home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr49 / pgp23src.zip / PGP.EL2 < prev    next >
Lisp/Scheme  |  1993-06-15  |  7KB  |  176 lines

  1. Newsgroups: alt.security.pgp
  2. From: mpf@medg.lcs.mit.edu (Michael P. Frank)
  3. Subject: New version of Emacs interface to PGP
  4. In-Reply-To: dec@alex.com's message of Wed, 3 Mar 1993 14:06:47 +0000
  5. Organization: MIT Laboratory for Computer Science
  6. Distribution: alt
  7. Date: Thu, 4 Mar 1993 22:01:03 GMT
  8.  
  9. Here's a somewhat improved version of my Emacs interface to PGP,
  10. pgp.el-0.2.
  11.  
  12. Some bugs are fixed since the last version. The main improvement is
  13. that if you have ange-ftp loaded, then pgp-set-passphrase will use it
  14. to prompt for your passphrase invisibly.
  15.  
  16. After loading this up, type C-c p h for a usage summary.
  17.  
  18. Consider this a beta release. Some egregious known bugs are:
  19.  
  20.     * Other users on the system can see your pass phrase using
  21.         "ps" and fortuitous timing.
  22.     * After decrypting, pgp's output "Pass phrase is good." is
  23.         stuck on the beginning of the plaintext.
  24.  
  25. Mike
  26. ========== cut here =============
  27. ;;;
  28. ;;; pgp.el-0.2 -- Emacs support for PGP 2.1
  29. ;;;
  30. ;;; Changes from 0.1:
  31. ;;;   pgp-clear-passphrase bug fixed.
  32. ;;;   If ange-ftp is loaded, password is entered invisibly.
  33. ;;;   On-line help.
  34. ;;;   Immediately after signing in place, C-c p k can be used to delete
  35. ;;;     pgp status garbage.
  36. ;;;
  37. ;;; 0.1 Changes from 0.0:
  38. ;;;   Inconsistent naming of pgp-set-passphrase fixed.
  39. ;;;
  40. ;;;          WARNING: Security Holes!
  41. ;;;
  42. ;;; People can see your PGP passphrase if:
  43. ;;; * You don't have ange-ftp and they see you typing in your passphrase.
  44. ;;; * They (intentionally or accidentally) do a "ps" (with appropriate options)
  45. ;;;     on your machine while you're decrypting/signing.
  46. ;;; * They type C-h v pgp-passphrase after you've entered it.
  47. ;;;
  48. ;;; Plus the system suffers from all the normal Unix and X-windows
  49. ;;; security holes.
  50. ;;; 
  51. ;;; Please report any bugs to mpf@medg.lcs.mit.edu.
  52. ;;; You can finger me for my public key.
  53. ;;;
  54.  
  55. (defvar pgp-passphrase nil
  56.   "Variable used internally by the Emacs PGP interface to hold
  57. the user's pass phrase.")
  58.  
  59. (defun pgp-set-passphrase ()
  60.   "Prompts for PGP pass phrase. If ange-ftp is loaded, password is invisible."
  61.   (interactive)
  62.   (setq pgp-passphrase
  63.     (if (boundp 'ange-ftp-version)
  64.         (ange-ftp-read-passwd "PGP pass phrase (invisible): ")
  65.       (read-string "PGP pass phrase (not invisible): "))))
  66.  
  67. (defun pgp-clear-passphrase ()
  68.   "Clears the PGP pass phrase."
  69.   (interactive)
  70.   (setq pgp-passphrase nil))
  71.  
  72. (defun pgp-ensure-passphrase ()
  73.   "Not an interactive command. If the passphrase is not set, prompts for it."
  74.   (if (not pgp-passphrase)
  75.       (call-interactively 'pgp-set-passphrase)))
  76.  
  77. (defun pgp-encrypt-region (start end pgp-user-id &optional flag)
  78.   "Encrypt the region using PGP. Prompts for a PGP user ID.
  79. With prefix arg, puts result in serparate window.
  80. Noninteractive args are START, END, PGP-USER-ID, and optional FLAG."
  81.   (interactive "r\nsUser ID to encrypt to: \nP")
  82.   (shell-command-on-region start end (concat "pgp -fea " pgp-user-id)
  83.                (not flag)))
  84.  
  85. (defun pgp-decrypt-region (start end &optional flag)
  86.   "Decrypt the region using PGP. Prompts for the user's pass phrase,
  87. if not already known.  With prefix arg, puts result in separate window.
  88. Noninteractive args are START and END and optional FLAG."
  89.   (interactive "r\nP")
  90.   (pgp-ensure-passphrase)
  91.   (shell-command-on-region start end
  92.                (concat "pgp -f -z \"" pgp-passphrase "\"")
  93.                (not flag)))
  94.  
  95. (defun pgp-sign-and-encrypt-region (start end pgp-user-id &optional flag)
  96.   "Sign and encrypt the region using PGP. Prompts for a user to
  97. encrypt to and a pass phrase, if not already known.
  98. With prefix arg puts result in separate window. 
  99. Noninteractive args are START, END, and PGP-USER-ID, and optional FLAG."
  100.   (interactive "r\nsUser ID to encrypt to: \nP")
  101.   (pgp-ensure-passphrase)
  102.   (shell-command-on-region start end (concat "pgp -safe " pgp-user-id
  103.                          " -z \"" pgp-passphrase "\"")
  104.                (not flag)))
  105.  
  106. (defun pgp-sign-region (start end &optional flag)
  107.   "Sign the region using PGP. Prompts for a pass phrase, if not already
  108. Known. With prefix arg puts result in separate window.
  109. Noninteractive args are START and END and optional FLAG."
  110.   (interactive "r\nP")
  111.   (pgp-ensure-passphrase)
  112.   (shell-command-on-region start end (concat "pgp -saft +clearsig=on"
  113.                          " -z \"" pgp-passphrase "\"")
  114.                (not flag)))
  115.  
  116. (defun pgp-verify-region (start end)
  117.   "Verify the signature on the text in the given region using PGP."
  118.   (interactive "r")
  119.   (shell-command-on-region start end "pgp -f"))
  120.  
  121. (defun pgp-describe ()
  122.   "Describe the PGP package.
  123.  
  124. Quick usage summary:
  125.  
  126. Default
  127. Key
  128. Binding  Command name                 Description
  129. =======  ===========================  =========================================
  130. C-c p p  pgp-set-passphrase           Prompts for entry of passphrase. With
  131.                                        ange-ftp loaded, this is invisible.
  132. C-c p c  pgp-clear-passphrase         Clears the passphrase from emacs memory.
  133.                                        (Not very thoroughly; see below.)
  134. C-c p e  pgp-encrypt-region           Prompts for recipient. Output in place
  135.                                        unless prefixed.
  136. C-c p d  pgp-decrypt-region           Prompts for passphrase if unknown.
  137.                                        Output in place unless prefixed.
  138. C-c p s  pgp-sign-region              Uses CLEARSIG. Prompts for passphrase
  139.                                        if unknown. Output in place unless C-u.
  140. C-c p S  pgp-sign-and-encrypt-region  Prompts for recipient and passphrase if
  141.                                        unknown. Output in place unless C-u.
  142. C-c p v  pgp-verify-region            Checks signature for validity. Output in
  143.                                        separate window.
  144. C-c p k  pgp-kill-status              Done immediately after C-c p s,
  145.                                        kills the PGP status information.
  146. C-c p h  pgp-describe                 Show this documentation.
  147.  
  148. WARNING: Security Holes:
  149. People can see your PGP passphrase if:
  150. * You don't have ange-ftp and they see you typing in your passphrase.
  151. * They (intentionally or accidentally) do a \"ps\" (with appropriate options)
  152.     on your machine while you're decrypting/signing.
  153. * They type C-h v pgp-passphrase after you've entered it.
  154.  
  155. Plus the system suffers from all the normal Unix and X-windows
  156. security holes.
  157.  
  158. More documentation to come."
  159.   (interactive)
  160.   (describe-function 'pgp-describe))
  161.  
  162. (global-set-key "\C-cpp" 'pgp-set-passphrase)
  163. (global-set-key "\C-cpc" 'pgp-clear-passphrase)
  164. (global-set-key "\C-cpe" 'pgp-encrypt-region)
  165. (global-set-key "\C-cpd" 'pgp-decrypt-region)
  166. (global-set-key "\C-cps" 'pgp-sign-region)
  167. (global-set-key "\C-cpS" 'pgp-sign-and-encrypt-region)
  168. (global-set-key "\C-cpv" 'pgp-verify-region)
  169. (global-set-key "\C-cpk" 'pgp-kill-status)
  170. (global-set-key "\C-cph" 'pgp-describe)
  171. (global-set-key "\C-cp?" 'pgp-describe)
  172. --
  173.    , ,                       __               MIT Lab for Computer Science
  174.   /|/| .  _ |_   _   _  |   |_  _  _  ,_  |,  mpf@medg.lcs.mit.edu
  175.  / | | | (_ | | (_| (-' |   |  |  (_| | | |\  (Finger for PGP Public Key)
  176.